import Vue from 'vue'

// 1. 导入并绑定Vuex
import Vuex from 'vuex'
Vue.use(Vuex)

// 2. 定义数据存储仓库state
const state = {
  username: ''
}

// 3. 定义用于修改数据的方法
const mutations = {
  setUsername: (state, username) => {
    state.username = username
    localStorage.setItem('username', username)
  }
}

// 4. 异步修改数据
const actions = {}

// 5. 计算属性
const getters = {
  username: (state) => localStorage.getItem('username')
}

// 6. 导出store实例
export default new Vuex.Store({
  state,
  getters,
  actions,
  mutations
})